package com.hl.web.fore;

import com.hl.pojo.ConsultationAppointment;
import com.hl.service.ConsultationAppointmentService;
import com.hl.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalUnit;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/consultationAppointment")
// 咨询预约控制器
public class ConsultationAppointmentController {
    @Autowired
    private ConsultationAppointmentService consultationAppointmentService;

    @PostMapping("/add")
    public ResultEntity add(@RequestBody ConsultationAppointment consultationAppointment){
//        Date date = new Date();
//        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        consultationAppointment.setTime(s.format(date));
        consultationAppointmentService.add(consultationAppointment);
        return ResultEntity.ok();
    }

    @GetMapping("/findAll")
    public ResultEntity findAll(Integer id){
        List<ConsultationAppointment> list = consultationAppointmentService.findAll(id);
        for(int i=0;i<list.size();i++){
            Date date = list.get(i).getTime2();
            date.setTime(date.getTime()+1000*60*60);
            list.get(i).setTime1(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
        }
        return ResultEntity.ok(list);
    }
    @GetMapping("/findAll1")
    public ResultEntity findAll1(Integer id){
        List<ConsultationAppointment> list = consultationAppointmentService.findAll1(id);
        for(int i=0;i<list.size();i++){
            Date date = list.get(i).getTime2();
            date.setTime(date.getTime()+1000*60*60);
            list.get(i).setTime1(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
        }
        return ResultEntity.ok(list);
    }
    @GetMapping("/findAll2")
    public ResultEntity findAll2(){
        return ResultEntity.ok( consultationAppointmentService.findAll2()
);
    }
    @GetMapping("/findAll3")
    public ResultEntity findAll3(String id){
        return ResultEntity.ok( consultationAppointmentService.findAll3(id)
        );
    }

    @GetMapping("/del")
    public ResultEntity del(Integer id){
        consultationAppointmentService.del(id);
        return ResultEntity.ok();
    }
    @PostMapping("/update")
    public ResultEntity update(@RequestBody ConsultationAppointment consultationAppointment){
        consultationAppointmentService.update(consultationAppointment);
        return ResultEntity.ok();
    }

}
